package com.atguigu.orderservice.service.impl;

import com.atguigu.commonutils.orderVo.CourseOrdervo;
import com.atguigu.commonutils.orderVo.MemberOrdertvo;
import com.atguigu.orderservice.entity.Order;
import com.atguigu.orderservice.feign.EduCourseFeign;
import com.atguigu.orderservice.feign.MemberFeign;
import com.atguigu.orderservice.mapper.OrderMapper;
import com.atguigu.orderservice.service.OrderService;
import com.atguigu.orderservice.utils.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.OrderUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author lzc
 * @since 2021-01-13
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private EduCourseFeign eduCourseFeign;

    @Autowired
    private MemberFeign memberFeign;

    /**
     * 生成订单
     * @param courseId
     * @param memberId
     * @return
     */
    @Override
    public String saveOrder(String courseId, String memberId) {
        //远程调用查询课程
        CourseOrdervo courseOrdervo = eduCourseFeign.getCourseOrdervo(courseId);
        //远程调用查询会员信息
        MemberOrdertvo memberOrdertvo = memberFeign.memberInfo(memberId);
        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseOrdervo.getTitle());
        order.setCourseCover(courseOrdervo.getCover());
        order.setTeacherName(courseOrdervo.getTeacherName());
        order.setMemberId(memberId);
        order.setNickname(memberOrdertvo.getNickname());
        order.setMobile(memberOrdertvo.getMobile());
        order.setTotalFee(courseOrdervo.getPrice());
        order.setPayType(1);
        order.setStatus(0);
        this.save(order);
        return order.getOrderNo();
    }
}
